#ifndef JVM_CLASSFILEPARSER_H
#define JVM_CLASSFILEPARSER_H

#include "classFileStream.h"
#include "oops/instanceKlass.h"
#include "oops/constantPool.h"
#include "oops/constMethod.h"
#include "utilities/constantTag.h"


class ClassFileParser
{

private:
    ClassFileStream *_stream; // Actual input stream
    Array<Method*>* _methods;

    InstanceKlass* klass;

    enum
    {
        LegalClass,
        LegalField,
        LegalMethod
    }; // used to verify unqualified names

public:
    // Constructor
    ClassFileParser(ClassFileStream *stream) : _stream(stream)
    {
        parse_stream(stream);
    }

    //~ClassFileParser();

    void parse_stream(ClassFileStream * stream);

    ConstantPool *parse_constant_pool(ClassFileStream * stream);

    // Interface parsing
    void parse_interfaces(ClassFileStream * stream, const int itfs_len);

    void parse_fields(ClassFileStream * stream);

    // Method parsing
    Method* parse_method(ClassFileStream* cfs,ConstantPool* cp);

    void parse_methods(ClassFileStream* cfs,ConstantPool* cp);

    void parse_linenumber_table(u4 code_attribute_length, u4 code_length);

    void parse_localvariable_table(ClassFileStream* cfs);

    void parse_classfile_attributes(ClassFileStream* cfs,ConstantPool* cp);

    void parse_classfile_sourcefile_attribute(ClassFileStream* cfs,ConstantPool* cp);

    InstanceKlass* create_instance_klass();
};

#endif